//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.app.twth.satoprinter.runnable;

import android.os.Process;
import android.util.Log;

import com.app.twth.satoprinter.connectivity.ConnectivityManager;

import java.util.concurrent.BlockingQueue;

public class PrintRunnable implements Runnable {
    private static final String TAG = PrintRunnable.class.getSimpleName();
    ConnectivityManager connectivityManager;
    private final BlockingQueue<byte[]> printQueue;

    public PrintRunnable(BlockingQueue<byte[]> queue, ConnectivityManager connectivityManager) {
        this.printQueue = queue;
        this.connectivityManager = connectivityManager;
    }

    public void run() {
        try {
            byte[] printJob = null;
            Process.setThreadPriority(10);

            while (!Thread.currentThread().isInterrupted()) {

                try {
                    printJob = (byte[]) this.printQueue.take();
                    if (printJob != null && printJob.length > 0) {
                        Log.e(TAG, "222write:" + "process");
                        this.connectivityManager.write(printJob);
                    }
                } catch (Exception e1) {
                    e1.printStackTrace();
                    //恢复中断状态
                    Log.e(TAG, "恢复中断状态");
                    Thread.currentThread().interrupt();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            try {
                //恢复中断状态
                Log.e(TAG, "恢复中断状态");
                Thread.currentThread().interrupt();
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }

    }
}
